<%-- 自定义实体添加页面 --%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>

<!DOCTYPE>
<html>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="bootstrap"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/system/custom/entity/entity_add.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
</head>
<body>
<!-- 加载列表操作 -->
<div class="button_list">
    <button id="save_entity" onclick="saveEntity()">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
                <span name="buTitle">保存</span>
            </span>
    </button>
    <button onclick="javascript:parent.closeTab();">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                <span name="buTitle">取消</span>
            </span>
    </button>
</div>

<div class="content row">
    <h3>基础信息</h3>
    <hr>
    <form role="form" class="entityForm" id="entity_form" method="post">
        <div class="form-group col-lg-5 col-md-10 pull-left" >
            <label class="pull-left">对象名称:<span style="color: red">*</span> </label>
            <input type="text" class="form-control" id="entity_inchinese" name="inchinese">
        </div>
        <div class="form-group col-lg-5 col-md-10" style="margin-left:-10px" >
            <label class="pull-left">英文名称:<span style="color: red">*</span></label>
            <input type="text" class="form-control" id="entity_name" name="name">
        </div>
        <div class="contentMid row">
            <span >所属模块:</span>
            <label class="checkbox-inline">
                <input type="checkbox" checked id="belongMudule" name="belongMudule" value="2">业务模块</input>
            </label>
            <br/>
            <span>其他选项:</span>
            <label class="checkbox-inline">
                <input type="checkbox" checked id="permission"  name="permission">是否受权限控制</input>
            </label>
            <label class="checkbox-inline">
                <input type="checkbox" id="useRecyclebin"  name="useRecyclebin">使用回收站</input>
            </label>
            <label class="checkbox-inline">
                <input type="checkbox" id="defineType"  name="defineType">可定义对象类型</input>
            </label>          　
            <label class="checkbox-inline">
                <input type="checkbox" id="canQuote" name="canQuote">对象可以被引用</input>
            </label>
            <label class="checkbox-inline">
                <input type="checkbox" id="defineApproval"  name="defineApproval">可以定义审批流</input>
            </label>
            <%--<br>
            <span>包含明细:</span>
            <input class="checkbox-inline">
                <input type="checkbox"  value="option2">是</input>
            </label>--%>
        </div>
    </form>
</div>

<script type="text/javascript">

    function validateMethod(){
        var flag = true;
        var inchinese = $("#entity_inchinese").val();
        var name = $("#entity_name").val();
        if(inchinese == ""){
            alert("对象名称不能为空!");
            flag = false;
            $("#entity_inchinese").focus();
            return flag;
        }
        if(name == ""){
            alert("英文名称不能为空!");
            flag = false;
            $("#entity_name").focus();
            return flag;
        }
        var parent=/^[A-Za-z0-9]+$/;
        if(!parent.test(name)){
            flag = false;
            alert("英文名称:只能输入英文!");
            $("#entity_name").focus();
            return flag;
        }
        return flag;
    }

    //自定义实体保存方法(xiaogq)
    function saveEntity(){
        var flag = validateMethod();
        if(flag){
            $("#save_entity").button('loading');
            var inchinese = $("#entity_inchinese").val();
            var name = $("#entity_name").val();
            var belongMudule = $("#belongMudule").val();
            var permission = $("#permission").is(':checked');
            var useRecyclebin = $("#useRecyclebin").is(':checked');
            var defineType = $("#defineType").is(':checked');
            var canQuote = $("#canQuote").is(':checked');
            var defineApproval = $("#defineApproval").is(':checked');
            $.ajax({
                type: 'POST',
                //contentType: 'application/json',
                url: getRootPath()+"/"+Constants.addEntityUrl,
                data : {inchinese:inchinese,name:name,belongMudule:belongMudule,permission:permission,useRecyclebin:useRecyclebin,defineType:defineType,canQuote:canQuote,defineApproval:defineApproval},
                dataType: 'json',
                success: function(data) {
                    var results = data.results;
                    if(results == "success"){
                        parent.closeTab(1);
                    }else{
                        alert("添加自定义实体未成功!");
                    }
                    $("#save_entity").button('reset');
                },
                error: function(data) {
                    $("#save_entity").button('reset');
                    alert("添加自定义实体发生错误!");
                }
            });
        }
    }
</script>
</body>
</html>
